<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: magic_color2.php 6757 2010-03-25 09:01:29Z cnteacher $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$mapping = array('blogid'=>'home_blogfield', 'tid'=>'home_thread');
if(!isset($mapping[$idtype])) {
	showmessage('magicuse_bad_object');
}
magic_check_idtype($id, $idtype);

if(submitcheck("usesubmit")) {

	$tablename = $mapping[$idtype];
	$_POST['color'] = intval($_POST['color']);
	DB::update($tablename, array('magiccolor'=>$_POST['color']), array($idtype=>$id, 'uid'=>$_G['uid']));

	$query = DB::query('SELECT * FROM '.DB::table('home_feed')." WHERE id='$id' AND idtype='$idtype' AND uid='$_G[uid]'");
	$feed = DB::fetch($query);
	if($feed) {
		$feed['body_data'] = unserialize($feed['body_data']);
		$feed['body_data'] = is_array($feed['body_data']) ? $feed['body_data'] : array();
		$feed['body_data']['magic_color'] = $_POST['color'];
		$feed['body_data'] = serialize($feed['body_data']);
		DB::update('home_feed', array('body_data'=>$feed['body_data']), array('feedid'=>$feed['feedid']));
	}

	magic_use($mid, array('id'=>$id, 'idtype'=>$idtype), true);
	showmessage('magicuse_success', dreferer());
}

?>